package com.nt.oam.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nt.common.enums.YesOrNoEnum;
import com.nt.oam.domain.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @Author JiangZhaoFeng
 * @Date 2025/3/3 9:23
 * @Description:
 */
//@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Service
public class UpdateProjectNameServiceImpl {
    @Autowired
    @Lazy
    private  AntHospitalOamRecordServiceImpl antHospitalOamRecordService;
    @Autowired
    @Lazy
    private AntSoftwareAssetServiceImpl antSoftwareAssetService;
    @Autowired
    @Lazy
    private  AntHardwareAssetServiceImpl antHardwareAssetService;
    @Autowired
    @Lazy
    private AntAccessDeviceAssetServiceImpl antAccessDeviceAssetService;
    @Autowired
    @Lazy
    private  AntDatabaseAssetServiceImpl antDatabaseAssetService;
    @Autowired
    @Lazy
    private  AntServerServiceImpl antServerService;

    // 1。 运维记录
    public void updateOamRecord(Long projectId, String projectName) {
        LambdaQueryWrapper<AntHospitalOamRecord> oamRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        oamRecordLambdaQueryWrapper.eq(AntHospitalOamRecord::getProjectId, projectId);
        oamRecordLambdaQueryWrapper.eq(AntHospitalOamRecord::getIsDeleted, YesOrNoEnum.NO.getCode());
        List<AntHospitalOamRecord> antHospitalOamRecordList = antHospitalOamRecordService.list(oamRecordLambdaQueryWrapper);
        if (Objects.nonNull(antHospitalOamRecordList) && antHospitalOamRecordList.size() > 0) {
            antHospitalOamRecordList.forEach(o -> {
                o.setProjectName(projectName);
                antHospitalOamRecordService.updateAntHospitalOamRecord(o);
            });
        }
    }

    // 4. 软件更新
    public void updateSoftware(Long projectId, String projectName) {
        LambdaQueryWrapper<AntSoftwareAsset> antSoftwareAssetLambdaQueryWrapper = new LambdaQueryWrapper<>();
        antSoftwareAssetLambdaQueryWrapper.eq(AntSoftwareAsset::getProjectId,projectId);
        antSoftwareAssetLambdaQueryWrapper.eq(AntSoftwareAsset::getIsDeleted, YesOrNoEnum.NO.getCode());
        List<AntSoftwareAsset> antSoftwareAssetList = antSoftwareAssetService.list(antSoftwareAssetLambdaQueryWrapper);
        if (Objects.nonNull(antSoftwareAssetList) && antSoftwareAssetList.size() > 0) {
            antSoftwareAssetList.forEach(s -> {
                s.setProjectName(projectName);
                antSoftwareAssetService.updateAntSoftwareAsset(s);
            });
        }
    }

    // 5. 硬件更新
    public void updateHardware(Long projectId, String projectName) {
        LambdaQueryWrapper<AntHardwareAsset> hardwareAssetLambdaQueryWrapper = new LambdaQueryWrapper<>();
        hardwareAssetLambdaQueryWrapper.eq(AntHardwareAsset::getProjectId,projectId);
        hardwareAssetLambdaQueryWrapper.eq(AntHardwareAsset::getIsDeleted, YesOrNoEnum.NO.getCode());
        List<AntHardwareAsset> antHardwareAssetList = antHardwareAssetService.list(hardwareAssetLambdaQueryWrapper);
        if (Objects.nonNull(antHardwareAssetList) && antHardwareAssetList.size() > 0) {
            antHardwareAssetList.forEach(h -> {
                h.setProjectName(projectName);
                antHardwareAssetService.updateAntHardwareAsset(h);
            });
        }

    }

    //6 设备接入
    public void updateDevice(Long projectId, String projectName) {
        LambdaQueryWrapper<AntAccessDeviceAsset> deviceAssetLambdaQueryWrapper = new LambdaQueryWrapper<>();
        deviceAssetLambdaQueryWrapper.eq(AntAccessDeviceAsset::getProjectId,projectId);
        deviceAssetLambdaQueryWrapper.eq(AntAccessDeviceAsset::getIsDeleted, YesOrNoEnum.NO.getCode());
        List<AntAccessDeviceAsset> antDeviceAssetList = antAccessDeviceAssetService.list(deviceAssetLambdaQueryWrapper);
        if (Objects.nonNull(antDeviceAssetList) && antDeviceAssetList.size() > 0) {
            antDeviceAssetList.forEach(h -> {
                h.setProjectName(projectName);
                antAccessDeviceAssetService.updateAntAccessDeviceAsset(h);
            });
        }

    }

    // 7 数据库
    public void updateDatabase(Long projectId, String projectName) {
        LambdaQueryWrapper<AntDatabaseAsset> databaseAssetLambdaQueryWrapper = new LambdaQueryWrapper<>();
        databaseAssetLambdaQueryWrapper.eq(AntDatabaseAsset::getProjectId,projectId);
        databaseAssetLambdaQueryWrapper.eq(AntDatabaseAsset::getIsDeleted, YesOrNoEnum.NO.getCode());
        List<AntDatabaseAsset> antDatabasewareAssetList = antDatabaseAssetService.list(databaseAssetLambdaQueryWrapper);
        if (Objects.nonNull(antDatabasewareAssetList) && antDatabasewareAssetList.size() > 0) {
            antDatabasewareAssetList.forEach(h -> {
                h.setProjectName(projectName);
                antDatabaseAssetService.updateAntDatabaseAsset(h);
            });
        }
    }

    // 8 服务器信息
    public void updateServer(Long projectId, String projectName) {
        LambdaQueryWrapper<AntServer> serverAssetLambdaQueryWrapper = new LambdaQueryWrapper<>();
        serverAssetLambdaQueryWrapper.eq(AntServer::getProjectId,projectId);
        serverAssetLambdaQueryWrapper.eq(AntServer::getIsDeleted, YesOrNoEnum.NO.getCode());
        List<AntServer> antHardwareAssetList = antServerService.list(serverAssetLambdaQueryWrapper);
        if (Objects.nonNull(antHardwareAssetList) && antHardwareAssetList.size() > 0) {
            antHardwareAssetList.forEach(h -> {
                h.setProjectName(projectName);
                antServerService.updateAntServer(h);
            });
        }
    }
}


